<?php

namespace rongyun;

use yii\base\InvalidConfigException;

/**
 * 融云Server API客户端
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class RongCloud extends \rongyun\components\BaseComponent {

    public function __construct($transport = null, $config = array()) {
        parent::__construct($config);
        if ($transport !== null) {
            return $this->createTransport([
                'class' => $transport
            ]);
        }
    }

    /**
     * Initializes the object.
     * This method is invoked at the end of the constructor after the object is initialized with the
     * given configuration.
     */
    public function init() {
        if (!$this->appKey || !$this->appSecret === null) {
            throw new InvalidConfigException('The Rongyun `appKey` and `appSecret` property must be set.');
        }
    }

    public function getUser() {
        return $this->createTransport([
            'class' => 'User'
        ]);
    }

    public function getMessage() {
        return $this->createTransport([
            'class' => 'Message'
        ]);
    }

    public function getWordfilter() {
        $Wordfilter = new Wordfilter($this);
        return $Wordfilter;
    }

    public function getGroup() {
        $Group = new Group($this);
        return $Group;
    }

    public function getChatroom() {
        $Chatroom = new Chatroom($this);
        return $Chatroom;
    }

    public function getPush() {
        $Push = new Push($this);
        return $Push;
    }

    public function getSms() {
        $SMS = new SMS($this);
        return $SMS;
    }

}
